﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;


namespace WindowsFormsApplication1.Forms
{
    public partial class frmParam : Form
    {
        String MAXLINEA;
        String MAXDIGIT;
        String MAXID;
        String MAXPAL;

        public frmParam()
        {
            InitializeComponent();
            cargarParametros();
        }

        private void cargarParametros()
        {
            ArrayList lineas = new ArrayList();
            //StreamReader f = new StreamReader(new FileStream("..\\..\\..\\param.txt", FileMode.Open));
            StreamReader f = new StreamReader(new FileStream("param.txt", FileMode.Open));

            String linea;
            while ((linea = f.ReadLine()) != null)
            {
                lineas.Add(linea);
                if (linea.Contains("MAXLINEA"))
                {
                    MAXLINEA = linea.Substring(9);
                    txtMaxLinea.Text = MAXLINEA;
                }
                else if (linea.Contains("MAXDIGIT"))
                {
                    MAXDIGIT = linea.Substring(9);
                    txtMaxDigit.Text = MAXDIGIT;
                }
                else if (linea.Contains("MAXID"))
                {
                    MAXID = linea.Substring(6);
                    txtMaxId.Text = MAXID;
                }
            }

            f.Close();

        }

        private void btnGuardar_Click(object sender, EventArgs e)
        {
            //using (StreamWriter f = new StreamWriter(new FileStream("..\\..\\..\\param.txt", FileMode.Create)))
            using (StreamWriter f = new StreamWriter(new FileStream("param.txt", FileMode.Create)))
            {
                String param = "MAXLINEA;" + txtMaxLinea.Text + "\r\n" +
                               "MAXDIGIT;" + txtMaxDigit.Text + "\r\n" +
                               "MAXID;" + txtMaxId.Text + "\r\n";
                f.Write(param);
                f.Close();
            }
            this.Close();
        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
